package com.ymatou.iapi.csim.testcase;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.csim.parameter.SaveOrUpdateDiscourseCategoryBean;
import com.ymatou.iapi.csim.service.SaveOrUpdateDiscourseCategoryCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.CsimCallService;
import com.ymttest.database.model.ymt_discourse;
import com.ymttest.database.model.ymt_discoursecategory;
import com.ymttest.database.sqlwapper.CSIM.ymt_cssessionWapper;
import com.ymttest.database.sqlwapper.CSIM.ymt_discoursecategoryWapper;
import com.ymttest.database.sqlwapper.CSIM.ymt_onlinecsWapper;
import com.ymttest.utils.EnvSetup;
import com.ymttest.utils.TestDataManager;
/**
*新增或更新话术分类
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_SaveOrUpdateDiscourseCategory{
	private static SaveOrUpdateDiscourseCategoryBean bean;
	private static SaveOrUpdateDiscourseCategoryCall call;
	private Integer csId=Integer.parseInt(EnvSetup.getData("csId").toString());
	private ymt_discoursecategoryWapper discoursecategoryWapper=new ymt_discoursecategoryWapper();
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("新增或更新话术分类");
	}

	@Before
	public void caseUp() {
		bean=new SaveOrUpdateDiscourseCategoryBean();
		call=new SaveOrUpdateDiscourseCategoryCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(call.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_SaveOrUpdateDiscourseCategory_1() {
		Logger.start(true,"新增或更新话术分类-验证不存在，新增");
		try {
			
			bean.setCategoryId(TestDataManager.getRandomUUID().toString());
			bean.setTitle("自动化测试_"+TestDataManager.getRandomNum(5));
			bean.setCsId(csId);
			bean.setSort(1);
			bean.setRoleType("MAIJIA_KEFU");
			call.setData(bean);
			call.callService();	
			//验证
			Logger.verifyEquals("0", call.getResult().get("ErrorCode").toString(), "验证errorCode");
			Logger.verifyEquals(true, call.getResult().get("Success"), "验证Success");
			Logger.verifyEquals("200", call.getStatus(), "验证Status");
			ymt_discoursecategory category=discoursecategoryWapper.selectByPrimaryKey(bean.getCategoryId());
			Logger.verifyEquals(bean.getCsId(), category.getCsId(), "验证CSId");
			Logger.verifyEquals(bean.getTitle(), category.getTitle(), "验证Title");
			Logger.verifyEquals(bean.getSort(), category.getSort(), "验证Sort");
			Logger.verifyEquals(bean.getRoleType(), category.getRoleType(), "验证RoleType");
			Logger.verifyEquals(0, category.getAction(), "验证Action");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_SaveOrUpdateDiscourseCategory_2() {
		Logger.start(true,"新增或更新话术分类-验证不存在，更新");
		try {
			
			bean.setCategoryId(TestDataManager.getRandomUUID().toString());
			bean.setTitle("自动化测试_"+TestDataManager.getRandomNum(5));
			bean.setCsId(csId);
			bean.setSort(1);
			bean.setRoleType("MAIJIA_KEFU");
			call.setData(bean);
			call.callService();	
			bean.setTitle("自动化测试_"+TestDataManager.getRandomNum(5));
			call.setData(bean);
			call.callService();	
			//验证
			Logger.verifyEquals("0", call.getResult().get("ErrorCode").toString(), "验证errorCode");
			Logger.verifyEquals(true, call.getResult().get("Success"), "验证Success");
			Logger.verifyEquals("200", call.getStatus(), "验证Status");
			ymt_discoursecategory category=discoursecategoryWapper.selectByPrimaryKey(bean.getCategoryId());
			Logger.verifyEquals(bean.getCsId(), category.getCsId(), "验证CSId");
			Logger.verifyEquals(bean.getTitle(), category.getTitle(), "验证Title");
			Logger.verifyEquals(bean.getSort(), category.getSort(), "验证Sort");
			Logger.verifyEquals(bean.getRoleType(), category.getRoleType(), "验证RoleType");
			Logger.verifyEquals(0, category.getAction(), "验证Action");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}